#pragma once

#include <SDL_opengl.h>
#include "glc/texturegroup.h"
#include "tile.h"

#include <libnoise/noise.h>



namespace Demo {

/**
 * @brief The Map class keeps global map
 */
class Map
{
public:
    Map();
    ~Map();

    void create(int width, int height);
    void destroy();

    GLC::Texture2DRef getTileTexture(int x, int y) const;

    int width() const;
    int height() const;
    void render() const;


private:
    Tile& at(int x, int y);
    const Tile& at(int x, int y) const;

    double mix(double x0,double x1,double y0,double y1,double measure);

    void renderTiles() const;

    void setTileTexture(int x, int y, GLC::Texture2DRef texture);

    float hat(int x,int y);

    std::vector<Tile> _tiles;
    int _width;
    int _height;
    std::unique_ptr<GLC::TextureGroup> _texgroup;

    // related to rendering (display lists optimization)
    mutable bool _hasChanged;
    mutable GLuint _displayList;

    std::vector<float> _height_map;


};

} // namespace Demo
